<?php
    class Chat {
        // ATRIBUT
        public $database;
        public $session;

        // METHOD
        public function __construct($database,$session) {
            $this->database = $database;
            $this->session = $session;
        }

        public function getFollowing() {
            $return = "Following :<br/>";

            $query = "SELECT * FROM ".$this->database->t_follow." WHERE username='".$this->session->username."'";
            $result = $this->database->execQuery($query);

            $count = mysql_num_rows($result);
            if ($count==0) {
                $return .= "-<br/>";
            }
            else {
                for ($i=0;$i<$count;$i++) {
                    $return .= "<a style='cursor:pointer;' onclick='newChat(\"".(mysql_result($result, $i, 'follow'))."\")'>";
                    $return .= "<b>".mysql_result($result, $i, "follow")."</b>";
                    $return .= "</a></br>";
                }
            }
            return $return;
        }

        public function getFollower() {
            $return = "Follower :<br/>";

            $query = "SELECT * FROM ".$this->database->t_follow." WHERE follow='".$this->session->username."'";
            $result = $this->database->execQuery($query);

            $count = mysql_num_rows($result);
            if ($count==0) {
                $return .= "-<br/>";
            }
            else {
                for ($i=0;$i<$count;$i++) {
                    $return .= "<a style='cursor:pointer;' onclick='newChat(\"".(mysql_result($result, $i, 'username'))."\")'>";
                    $return .= "<b>".mysql_result($result, $i, "username")."</b>";
                    $return .= "</a></br>";
                }
            }
            return $return;
        }
    }
?>
